//
//  TimeInteval.m
//  HimalayaMusic
//
//  Created by dllo on 16/1/9.
//  Copyright © 2016年 WXCLegendary. All rights reserved.
//

#import "TimeInteval.h"

@implementation TimeInteval
+(NSString *)shareGetUTCFormateDate:(id)timeSecond
{
    //时间戳转标准时间
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    //设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    NSString *date = [NSString stringWithFormat:@"%@",[formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:[timeSecond longLongValue]]]];
    NSDate *newsDateFormatted = [formatter dateFromString:date];
    //    NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
    //    [dateFormatter setTimeZone:timeZone];
    
    NSDate* current_date = [[NSDate alloc] init];
    
    NSTimeInterval time=[current_date timeIntervalSinceDate:newsDateFormatted];//间隔的秒数
    long year = ((long)time)/(3600*24*30*12);
    long month=((long)time)/(3600*24*30);
    long days=((long)time)/(3600*24);
    long hours=((long)time)%(3600*24)/3600;
    long minute=((long)time)%(3600*24)/60;
    //NSLog(@"time=%.2f",(double)time);
    
    NSString *dateContent;
    if (year != 0) {
        dateContent = [NSString stringWithFormat:@"%ld%@",year,@"年前"];
    }else if(month!=0){
        
        dateContent = [NSString stringWithFormat:@"%ld%@",month,@"个月前"];
        
    }else if(days!=0){
        
        dateContent = [NSString stringWithFormat:@"%ld%@",days,@"天前"];
    }else if(hours!=0){
        
        dateContent = [NSString stringWithFormat:@"%ld%@",hours,@"小时前"];
    }else{
        
        dateContent = [NSString stringWithFormat:@"%ld%@",minute,@"分钟前"];
    }
    return dateContent;
}

@end
